package homework13;

import java.util.ArrayList;
import java.util.Collections;

public class home02 extends Thread {
    ArrayList<Integer> list;
    Integer sumprize = 0;

    Integer maxprize=0;

    public Integer getMaxprize() {
        return maxprize;
    }

    public void setMaxprize(Integer maxprize) {
        this.maxprize = maxprize;
    }

    public home02(ArrayList<Integer> list) {
        this.list = list;
    }

    public Integer getSumprize() {
        return sumprize;
    }

    public void setSumprize(Integer sumprize) {
        this.sumprize = sumprize;
    }

    @Override
    public void run() {
        StringBuilder sb = new StringBuilder();
        sb.append(getName() + ":");
        while (true) {
            synchronized (homework13.home01.class) {
                if (list.size() == 0) {
                    break;
                }
                Collections.shuffle(list);
                Integer prize = list.remove(0);
                if (prize > maxprize) {
                   setMaxprize(prize);
                }
                setSumprize(sumprize + prize);
//                System.out.print(prize+",");
                sb.append(prize + ",");
                try {
                    sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        sb.append("总计额为" + getSumprize() + "元");
        System.out.println(sb);
    }
}
